package org.one.stone.soup.grfxML;

import org.one.stone.soup.mjdb.data.field.DataLinker;
import org.one.stone.soup.mjdb.data.field.Field;
import org.one.stone.soup.mjdb.data.field.LockException;
import org.one.stone.soup.mjdb.data.field.NullField;
import org.one.stone.soup.xml.XmlElement;
  /*
 * Copyright 2000-2001 Wet-Wired.com Ltd.,
 * Portsmouth England
 * All rights reserved.
 */

/**
	*
	* @author Nik Cross
*/
public abstract class DataAnchor extends NullField implements ITag{
	public static String DEFAULT_ID="_Anchor";
		DataState trigger = new DataState(false);
public DataAnchor() {
	try{
		setId(DEFAULT_ID,this);
	}
	catch(LockException le){} //Dummy catch
}
public boolean buildFromElement(XmlElement element){
	if(element == null)
			return false;

		String eleName = element.getName();

		if(eleName.equals(Token.TRIGGER))
		{
			trigger = new DataState(false);
			trigger.buildFromgrfxML(element);
		}
		else
			return false;

		return true;
}
public boolean copyFromElement(XmlElement element){
	if(element == null)
			return false;

		String eleName = element.getName();

		if(eleName.equals(Token.TRIGGER))
		{
			trigger.copyFromgrfxML(element);
		}
		else
			return false;

		return true;
}
public abstract DataAnchor getClone();
public abstract DataAnchor getClone(String path);
public void getClonedElements(String path,DataAnchor newAnchor)
{
	newAnchor.trigger = trigger.getClone(path);
}
public void getClonedElements(DataAnchor newAnchor)
{
	newAnchor.trigger = trigger.getClone();
}
public DataState getTrigger() {
	return trigger;
}
public void register(DataLinker store) {
	try{
		store.add(trigger,this);
	}
	catch(LockException le)
	{}//Dummy catch
}
public void replace(Field oldObj, Field newObj) {
	if(trigger==oldObj)
		trigger=(DataState)newObj;
}
public void resetChanged() {
	super.resetChanged();
	trigger.resetChanged();
}
protected void setTrigger(DataState newTrigger) {
	trigger = newTrigger;
}
public String togrfxML(String name) {
	String xml =trigger.togrfxML(Token.TRIGGER);
	return xml;
}
public String togrfxML(String name,TagModifier modifier) {
	return togrfxML(name);
}
public String toString()
{
	if(GrfxMLEngine.DEBUG)
		return(togrfxML( DEFAULT_ID.substring(1) ));

	String xml = "<"+DEFAULT_ID.substring(1)+"/>";

	return xml;
}
}
